import React from 'react'
import { Button, Card, NavBar } from 'antd-mobile'
import { useNavigate } from 'react-router-dom'
import { FilterOutline } from 'antd-mobile-icons'
import img from '../../img/tu.png'
import img1 from '../../img/tu2.png'
// function Index() {

//   let nav = useNavigate()
//   return (
//     <div>
//      <NavBar  right={<FilterOutline />} onBack={()=>nav(-1)}>搜索附近活动</NavBar>
//     </div>
//   )
// }

// export default Index
import { useEffect } from "react";
import styles from "./MapContainer.module.css";
import AMapLoader from "@amap/amap-jsapi-loader";

export default function MapContainer() {
  let map = null;
  let nav = useNavigate()
  useEffect(() => {
    window._AMapSecurityConfig = {
      securityJsCode: "35d1d0c2c97db1223a4c307fb468e57b",
    };
    AMapLoader.load({
      key: "0ffbedfa42d98e2bfd518dcd09a96a07", // 申请好的Web端开发者Key，首次调用 load 时必填
      version: "2.0", // 指定要加载的 JSAPI 的版本，缺省时默认为 1.4.15
      plugins: ["AMap.Scale"], //需要使用的的插件列表，如比例尺'AMap.Scale'，支持添加多个如：['...','...']
    })
      .then((AMap) => {
        var map = new AMap.Map('container', {
          resizeEnable: true,
          center: [116.397428, 39.90923],
          zoom: 13
        });

        map.clearMap();  // 清除地图覆盖物

        var markers = [{
          icon: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-1.png',
          position: [116.406315, 39.908775]
        }, {
          icon: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-2.png',
          position: [116.368904, 39.913423]
        }, {
          icon: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-3.png',
          position: [116.391467, 39.927761]
        }];

        // 添加一些分布不均的点到地图上,地图上添加三个点标记，作为参照
        markers.forEach(function (marker) {
          new AMap.Marker({
            map: map,
            icon: marker.icon,
            position: [marker.position[0], marker.position[1]],
            offset: new AMap.Pixel(-13, -30)
          });
        });



      })
      .catch((e) => {
        console.log(e);
      });

    return () => {
      map?.destroy();
    };
  }, []);

  let maplist = [
    {
      tu: img,
      title: '艺术展览',
      zi: 'Merufest 2024',
      man: '182 参与者',
      price: 289
    },
    {
      tu: img1,
      title: '专业研讨会',
      zi: '项目研究标题',
      man: '381 参与者',
      price: '免费'
    }
  ]
  return (
    <div style={{background:'#eee',height:'100vh'}}>
      <div>
        <NavBar right={<FilterOutline />} onBack={() => nav(-1)}>搜索附近活动</NavBar>
      </div>
      <div
        id="container"
        className={styles.container}
        style={{ height: "400px" }}
      ></div>
      <div>
        <b style={{margin:'17px'}}>附近活动</b>

        {
          maplist.map((item, index) => {
            return <Card style={{margin:'12px'}}> <div style={{ display: 'flex' }}>
              <img src={item.tu} alt="" style={{ marginRight: '15px' }} />
              <div>
                <p style={{color:'#ccc'}}>{item.title}</p>
                <p>{item.zi}</p>
                <p>{item.man}</p>
              </div>
            <Button style={{width:'60px',height:'30px',marginLeft:'100px',borderRadius:'20px'}}>{item.price}</Button>
            </div>


            </Card>
          })
        }

      </div>
    </div>


  );
}

